const app = getApp();
Page({
    data: {
        questionsList: [
            {
                id: 0,
                question: "象棋一词最早是在什么朝代出现的？",
                answers: ["明朝", "宋朝", "唐朝", "战国"],
                rightIndex: 3
            },
            {
                id: 1,
                question: "象棋有几种颜色的棋子？",
                answers: ["两种", "三种", "四种", "六种"],
                rightIndex: 0
            },
            {
                id: 2,
                question: "象棋对局中，“走田”的是哪个棋子？",
                answers: ["象", "车", "炮", "马"],
                rightIndex: 0
            },
            {
                id: 3,
                question: "象棋对局中，“走日”的是哪个棋子？",
                answers: ["象", "车", "炮", "马"],
                rightIndex: 0
            },
            {
                id: 4,
                question: "象棋有几种棋子？",
                answers: ["四种", "五种", "六种", "七种"],
                rightIndex: 3
            },
            {
                id: 5,
                question: "不能过河的棋子是？",
                answers: ["兵", "象", "炮", "马"],
                rightIndex: 1
            },
            {
                id: 6,
                question: "必须隔子才能吃子的是什么棋子？",
                answers: ["车", "马", "炮", "象"],
                rightIndex: 2
            },
            {
                id: 7,
                question: "不允许后退的是什么棋子？",
                answers: ["将", "士", "象", "马"],
                rightIndex: 0
            },
            {
                id: 8,
                question: "象棋棋盘中可落子的点一共有多少个？",
                answers: ["60", "7", "80", "90"],
                rightIndex: 3
            },
            {
                id: 9,
                question: "象棋棋盘有几根横线？",
                answers: ["6", "9", "12", "15"],
                rightIndex: 1
            }
        ],
        questionsItem: {},
        itemIndex: 0,
        showACPackage: null,
    },
    async onLoad(options) {
        const isCPackage = await app.helper.enterFromLiveRoom()
        if (isCPackage) {
            tt.switchTab({ url: '/pages/index/index' })
        }
        const { questionsList } = this.data
        this.setData({ questionsItem: questionsList.shift(), questionsList, showACPackage: isCPackage })
    },
    onSure() {
        const { questionsList, questionsItem } = this.data
        this.setData({
            questionsItem: questionsItem < questionsList - 1 ? questionsItem + 1 : 0,
            questionsItem: questionsList[questionsItem],
        })
    },
    doAnswer(e) {
        const { index } = e.target.dataset
        const { questionsList, questionsItem } = this.data
        const isSuccess = index === questionsItem.rightIndex
        tt.showModal({
            title: '提示',
            content: isSuccess ? "恭喜你,答对了!" : "很遗憾,答错了!",
            success: (res) => {
                if (res.confirm) {
                    this.setData({ questionsItem: questionsList.shift(), questionsList })
                }
            }
        });
    },


})